﻿using System;
using UnityEngine;


public class AndroidHelper
{

	private static AndroidHelper _instance;
	private AndroidJavaObject _androidJavaObj;

	private static AndroidJavaObject _internalJavaObj;
	private static AndroidJavaObject _adsManagerJavaObj;
	private static AndroidJavaObject _analyticsManagerJavaObj;
	private static AndroidJavaObject _permissonManagerJavaObj;
	private static AndroidJavaObject _moregameManagerJavaObj;
	private static AndroidJavaObject _iapManagerJavaObj;

//	private static string _internalPkgName = "com/common/android/jni/STSystemFunction";
//	private static string _internalPkgName = "com.common.android.jni.STSystemFunction";
	private static string _internalPkgName = "com.common.android.InternalInterfaceManager";
//	private static string _adsManagerPkgName = "com.common.android.unityplugins.UnityAdsManager";
	private static string _adsManagerPkgName = "com.common.android.ads.AdsManager";
//	private static string _analyticsManagerPkgName = "com.common.android.unityplugins.UnityAnalyticsManager";
	private static string _analyticsManagerPkgName = "com.common.android.analyticscenter.AnalyticsManager";

	private static string _permissionMangerPkgName = "com.common.android.permission.PermissionHelper";
	private static string _moregameMangerPkgName = "com.common.android.moregame.MoreGames";
	private static string _iapMangerPkgName = "com.common.android.iap.SSCIAPHelper";

	private AndroidHelper ()
	{
	}

	public static AndroidHelper getInstance(){
		if (_instance == null)
			_instance = new AndroidHelper ();
		return _instance;
	}

	public AndroidJavaObject getAndroidJavaObject(){
		if (_androidJavaObj == null) {
			AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 
			_androidJavaObj = jc.GetStatic<AndroidJavaObject>("currentActivity"); 
		}
		return _androidJavaObj;
	}

	public static AndroidJavaObject getObj(){
		AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 
		AndroidJavaObject _Obj = jc.GetStatic<AndroidJavaObject>("currentActivity");
		return _Obj;


	}

	public static AndroidJavaObject getInternalAndroidObject(){
		if (_internalJavaObj == null) {
			AndroidJavaClass jc = new AndroidJavaClass(_internalPkgName); 
			_internalJavaObj = jc.GetStatic<AndroidJavaObject>("instance");
		}
		return _internalJavaObj;
	}

	public static AndroidJavaObject getAdsManagerAndroidObject(){
		if (_adsManagerJavaObj == null) {
			AndroidJavaClass jc = new AndroidJavaClass(_adsManagerPkgName); 
			_adsManagerJavaObj = jc.GetStatic<AndroidJavaObject>("instance");
		}
		return _adsManagerJavaObj;
	}

	public static AndroidJavaObject getAnalyticsManagerAndroidObject(){
		if (_analyticsManagerJavaObj == null) {
			AndroidJavaClass jc = new AndroidJavaClass(_analyticsManagerPkgName); 
			_analyticsManagerJavaObj = jc.GetStatic<AndroidJavaObject>("instance");
		}
		return _analyticsManagerJavaObj;
	}

	public static AndroidJavaObject getPermissionManagerAndroidObject(){
		if (_permissonManagerJavaObj == null) {
			AndroidJavaClass jc = new AndroidJavaClass(_permissionMangerPkgName); 
			_permissonManagerJavaObj = jc.GetStatic<AndroidJavaObject>("instance");
		}
		return _permissonManagerJavaObj;
	}

	public static AndroidJavaObject getMoregamesManagerAndroidObject(){
		if (_moregameManagerJavaObj == null) {
			AndroidJavaClass jc = new AndroidJavaClass(_moregameMangerPkgName); 
			_moregameManagerJavaObj = jc.GetStatic<AndroidJavaObject>("instance");
		}
		return _moregameManagerJavaObj;
	}

	public static AndroidJavaObject getIapManagerAndroidObject(){
		if (_iapManagerJavaObj == null) {
			AndroidJavaClass jc = new AndroidJavaClass(_iapMangerPkgName); 
			_iapManagerJavaObj = jc.GetStatic<AndroidJavaObject>("instance");
		}
		return _iapManagerJavaObj;
	}

}


